#include "base_osd.h"

int prepare_user_buf(void *buf, uint32_t size_y, uint32_t size_uv)
{
  int ret;
  hb_vio_buffer_t *buffer = (hb_vio_buffer_t *)buf;

  if (buffer == NULL) return -1;

  buffer->img_info.fd[0] = ion_open();
  buffer->img_info.fd[1] = ion_open();

  ret = ion_alloc_phy(size_y, &buffer->img_info.fd[0], &buffer->img_addr.addr[0], &buffer->img_addr.paddr[0]);
  if (ret != 0) {
    printf("prepare user buf error ret:%d\n", ret);
    return ret;
  }

  ret = ion_alloc_phy(size_uv, &buffer->img_info.fd[1], &buffer->img_addr.addr[1], &buffer->img_addr.paddr[1]);
  if (ret != 0) {
    printf("prepare user buf error ret:%d\n", ret);
    return ret;
  }

  // printf("buf:y: vaddr = 0x%s paddr = 0x%ld; uv: vaddr = 0x%s, paddr = 0x%ld\n",
  // buffer->img_addr.addr[0], buffer->img_addr.paddr[0],
  // buffer->img_addr.addr[1], buffer->img_addr.paddr[1]);

  return 0;
}
